Trigger on Discussion / Comment creation

Hello,

I am trying to send email notifications when a new discussion and/or comment is created. I have the following questions about the discussion/comment triggers :

1) How can I get the object and the module associated to a comment trigger ? I.e. when the comment creation trigger fires, how do I get to the object that the comment was made on ?

2) When creating a discussion, a first comment is also created (can be empty string). Does it also generate a comment creation trigger, or only a discussion creation trigger ?

Thanks in advance for your advices.

Servanne.
sdauphin - Tue Oct 26 11:02:14 EDT 2010

Re: Trigger on Discussion / Comment creation
llandale - Tue Oct 26 15:58:51 EDT 2010

Have yet to deal with these new trigger events, but the following will surely work:

Trigger    trg = current;          if (null trg) halt() // ?Error possible?
Object  obj = object(trg); if (null obj) halt() // ?Error possible?
Module  mod = module(obj); if (null mod) halt() // ?Error possible?

 

  • Louie


and:

 

 

string NameAttr = attribute(trg) // Attr Name defined in trigger Scope, if any
     // for attr-save triggers
AttrDef    ad  = attrdef(trg); if (null ad) halt()      // ?Error? 
ValueNominated  = value(trg)    // pre-save attr value, what the user wants

 

Re: Trigger on Discussion / Comment creation
sdauphin - Thu Oct 28 10:33:46 EDT 2010

Louie,

This does not work ...

I have defined a Comment trigger :

trigger(NameTrig,project->"Proto"->module->all->formal->comment,post,create,9,DxlCode)

 


Then, I have the following code :

 

 

Object curObj
Module curMod
Discussion curDisc = null
Comment curCom = null
 
Trigger t = current; if (null t) {errorBox "Null Trigger";halt}
if (!null t) then {
    print "Trigger has fired !\n"
        curDisc = discussion(t); if (null curDisc) {errorBox "Null Discussion"}
        curCom = comment(t); if (null curCom) {errorBox "Null Comment";halt}
        if (null curDisc) {curDisc = curCom.discussion }
        if (null curDisc) {errorBox ("Null Discussion");halt()}
        print "Discussion Title : " curDisc.summary "\n"
        
        curObj = object(t); if (null curObj) {errorBox "Null Object";halt}      
        curMod = module(curObj); if (null curMod) {errorBox "Null Module";halt}         
        string NameAttr = attribute(t) // Attr Name defined in trigger Scope, if any
        print "NameAttr: " NameAttr "\n"



When adding a comment in an existing discussion, I see the "Trigger has fried" message, then I get an Exception error on the line where I print the discussion summary.

If I comment this line out, I get an error box "Null Object", from the next line of code.

I also tried to define the trigger like this :



 

 

trigger(NameTrig,project->"Proto"->module->all->formal->object->all->comment,post,create,9,DxlCode)


but I get the same results.

Any hint ?

Servanne.

 

Re: Trigger on Discussion / Comment creation
llandale - Fri Oct 29 12:31:32 EDT 2010

sdauphin - Thu Oct 28 10:33:46 EDT 2010

Louie,

This does not work ...

I have defined a Comment trigger :

trigger(NameTrig,project->"Proto"->module->all->formal->comment,post,create,9,DxlCode)

 


Then, I have the following code :

 

 

Object curObj
Module curMod
Discussion curDisc = null
Comment curCom = null
 
Trigger t = current; if (null t) {errorBox "Null Trigger";halt}
if (!null t) then {
    print "Trigger has fired !\n"
        curDisc = discussion(t); if (null curDisc) {errorBox "Null Discussion"}
        curCom = comment(t); if (null curCom) {errorBox "Null Comment";halt}
        if (null curDisc) {curDisc = curCom.discussion }
        if (null curDisc) {errorBox ("Null Discussion");halt()}
        print "Discussion Title : " curDisc.summary "\n"
        
        curObj = object(t); if (null curObj) {errorBox "Null Object";halt}      
        curMod = module(curObj); if (null curMod) {errorBox "Null Module";halt}         
        string NameAttr = attribute(t) // Attr Name defined in trigger Scope, if any
        print "NameAttr: " NameAttr "\n"



When adding a comment in an existing discussion, I see the "Trigger has fried" message, then I get an Exception error on the line where I print the discussion summary.

If I comment this line out, I get an error box "Null Object", from the next line of code.

I also tried to define the trigger like this :



 

 

trigger(NameTrig,project->"Proto"->module->all->formal->object->all->comment,post,create,9,DxlCode)


but I get the same results.

Any hint ?

Servanne.

 

Don't know. But I would try:
print "Discussion Title : " (curDisc.summary) "\n"
if that doesn't work try:
string Summary = curDisc.Summary
print "Discussion Title : " Summary "\n"

  • Louie

Re: Trigger on Discussion / Comment creation
TapasMondal - Mon Oct 15 03:39:05 EDT 2012

llandale - Fri Oct 29 12:31:32 EDT 2010
Don't know. But I would try:
print "Discussion Title : " (curDisc.summary) "\n"
if that doesn't work try:
string Summary = curDisc.Summary
print "Discussion Title : " Summary "\n"

  • Louie

Sir,
How can I get object info from comment trigger info?

I tried with
Trigger trg = current;
Object curObj
curObj =object(trg);

getting null object.
please help

Re: Trigger on Discussion / Comment creation
llandale - Mon Oct 15 15:22:12 EDT 2012

TapasMondal - Mon Oct 15 03:39:05 EDT 2012
Sir,
How can I get object info from comment trigger info?

I tried with
Trigger trg = current;
Object curObj
curObj =object(trg);

getting null object.
please help

You say you are writing your own Comment trigger? that code should get the Object associated with the trigger when it fires, so long as it is inside the trigger.